﻿#region Copyright(c) 2006 ZO, All right reserved.
// -----------------------------------------------------------------------------
// Copyright(c) 2006 ZO, All right reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   1.  Redistribution of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//   2.  Redistribution in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//   3.  The name of the author may not be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// -----------------------------------------------------------------------------
#endregion


#region Using directives

using ZO.SmartCore.Helpers;
using ZO.SmartCore.Xml;

#endregion

namespace ZO.SmartCore.Protocols.XMPP.Protocol.Common
{
    /// <summary>
    /// Encapsulates a message element. The message is used to send or receive data, without need of an immediate response.
    /// </summary>
    public abstract class BaseMessage : Stanza
    {

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseMessage"/> class.
        /// </summary>
        protected BaseMessage()
            : base("message")
        {
            this.GenerateID();
        } // Message
        #endregion

        #region Destructor

        #endregion

        #region Fields

        #endregion

        #region Events

        #endregion

        #region Operators

        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the type of the message.
        /// </summary>
        /// <value>The type.</value>
        public MessageType Type
        {
            get
            {
                return (MessageType)this.GetAttributeAsEnum("type", typeof(MessageType));
            }
            set
            {
                if (value == MessageType.Normal)
                {
                    this.RemoveAttribute("type");
                }
                else
                {
                    this.SetAttribute("type", ReflectionHelper.GetDescription(value));
                }
            }
        }

        /// <summary>
        /// contains human-readable XML character data that specifies the textual contents of the message.
        /// </summary>
        /// <value>The body.</value>
        public string Body
        {
            get
            {
                Element bodyString;

                bodyString = this["body"];

                if (bodyString == null)
                {
                    return "";
                }
                return bodyString.Value;
            }
            set
            {
                this["body"] = new Element("body", value);
            }
        }

        /// <summary>
        /// contains human-readable XML character data that specifies the topic of the message.
        /// </summary>
        /// <value>The subject.</value>
        public string Subject
        {
            get
            {
                Element tempString;

                tempString = this["subject"];

                if (tempString == null)
                {
                    return "";
                }
                return tempString.Value;
            }
            set
            {
                this["subject"] = new Element("subject", value);
            }
        }

        /// <summary>
        /// lement contains non-human-readable XML character data specifying an identifier
        /// that is used for tracking a conversation thread (sometimes referred to as 
        /// an "instant messaging session") between two entities.
        /// </summary>
        /// <value>The thread.</value>
        public string Thread
        {
            get
            {
                Element tempString;

                tempString = this["thread"];

                if (tempString == null)
                {
                    return "";
                }
                return tempString.Value;

            }
            set
            {
                this["thread"] = new Element("thread", value);
            }
        }
        #endregion

        #region Methods

        #endregion
    }
}
